/***************************************************************************
 *   Copyright (C) 2008 by Ivan Blagoev Topolsky   *
 *   ivan.topolsky@genebio.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef PEPTIDEFROMSEQUENCE_H
#define PEPTIDEFROMSEQUENCE_H

#include <boost/shared_ptr.hpp>

#include "peptide.h"
#include "dbsequence.h"


/**
  peptidefromsequence stores a peptide while also keeping additional information about it origin :
  - a pointer to the DBSequence from which this peptide comes from
  - a position inside said sequence

  the pointer type DBSequencePtr is a boost's shared pointer : even if the DBSequenceDigestor finishes, 
  the corresponding DBSequence won't be destroyed as long as a PeptideFromSequence is still refering to it.

	@author Ivan Topolsky,,, <ivan.topolsky@genebio.com>
*/

using namespace std;
namespace bol{

typedef boost::shared_ptr<DBSequence> DBSequencePtr;

class PeptideFromSequence : public Peptide{
  DBSequencePtr db_sequence;
  int m_position;

  void fromString(const string& seq);

public:
    PeptideFromSequence():Peptide(){
      m_position=0;
    }

    /**
     * constructor from a subset position in a DBSequence (dupicating the sequence)
     * start and end reduced aminoacid will be added if needed
     * @param dbseq 
     * @param pos 
     * @param len
     */
    PeptideFromSequence(const DBSequencePtr &dbseq, const int pos, const int len) : Peptide(*(dbseq->sequence()), pos, len) {
      setPosition (pos);
      setDBSequence (dbseq);
    }


  /**
   * set the DBSequence from which this peptide comes
   * @param dbseq 
   */
  void setDBSequence(const DBSequencePtr &dbseq) {
      db_sequence = dbseq;
  }
  
  /**
   * set the at which position inside DBSequence this peptide is found
   * @param theValue 
   */
  void setPosition(const int pos) {
      m_position = pos;
  }

  /**
   * 
   * @return  which DBSequence this peptides comes from
   */
  DBSequencePtr DBSequence() const {
      return db_sequence;
  }

  /**
   * 
   * @return  position at which the peptide can be found inside the DBSequence
   */
  int position() const {
      return m_position;
  }

};

}
#endif
